package com.example.project.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

public final class IntegerUtil {

	private static Logger logger = LoggerFactory.getLogger(IntegerUtil.class);
	private IntegerUtil() {
		throw new IllegalStateException("Utility class");
	}

	public static boolean isEmpty(Integer i){
		return i == null || i == 0;
	}
	
	public static boolean isNotEmpty(Integer i){
		return i != null && i > 0;
	}
	
	public static boolean isNull(Integer i){
		return i==null;
	}
	
	public static Integer getValue(Object i){
		try {
			String str = i.toString();
			if (str.contains(".")){
				str=str.substring(0,str.indexOf('.'));
			}
			return Integer.parseInt(str);
		} catch (Exception e) {
			logger.error("该参数不是数字:{}",e.getMessage());
			return null;
		}
	}

	public static Integer add(Integer i1,Integer i2){
		if (isEmpty(i1))
			i1 = 0;
		if (isEmpty(i2))
			i2 = 0;
		return i1+i2;
	}

	// 进行减法运算
	public static Integer sub(Integer i1, Integer i2){
		if (isEmpty(i1))
			i1 = 0;
		if (isEmpty(i2))
			i2 = 0;
		return i1 - i2;
	}
}
